﻿using AiShow.BLL;
using AiShow.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiShow.WebSite
{
    public partial class AvatarEdit : System.Web.UI.Page
    {
        IUserManager manager = new UserManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            //没有获取用户跳转到登录页面
            if (!IsPostBack) 
            {
                var user = IdentityManager.ReadUser();
                if (user == null)
                {
                    Response.Redirect("login.aspx?ReturnUrl=AvatarEdit.aspx");
                }
            }
        }

        protected void btnAvatar_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                //调用用户信息
                var user = IdentityManager.ReadUser();
                user.Avatar = hfAvatar.Value;
                var result = manager.EditAvatar(user);
                //获取操作结果
                if (result.StatusCode == Common.StatusCode.Succeed)
                {
                    Response.Redirect("Personal.aspx");
                }
                else
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "loginerror", $"alert('{result.Message}')", true);
                }


            }
        }
    }
}